import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/components/Home.vue'
import Analysis from '../views/components/Analysis.vue'
import XmlCode from '../views/components/XmlCode.vue'
import JavaCode from '../views/components/JavaCode.vue'
import Basic from "../views/components/Basic.vue";
import StaticAnalysis from "../views/components/StaticAnalysis.vue";
import CodeAnalysis from "../views/components/CodeAnalysis.vue";
import DynamicAnalysis from "../views/components/DynamicAnalysis.vue";
import DyAna from "../views/components/DyAna.vue";
import Model from "../views/components/Model.vue";
import Pdf from "../views/components/Pdf.vue";


const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      meta: { title: '首页',keepAlive:true  }
    },
    {
      path: '/analysis',
      name: 'analysis',
      component: Analysis,
      meta:{keepAlive:true },
      children: [
        {
          name: 'basic',
          path: 'basic',
          component: Basic,
          meta: { title: '信息',keepAlive:true  }
        },
        {
          name: 'staticAnalysis',
          path: 'staticAnalysis',
          component: StaticAnalysis,
          meta: { title: '应用权限',keepAlive:true  }
        },
        {
          name: 'codeAnalysis',
          path: 'codeAnalysis',
          component: CodeAnalysis,
          meta: { title: '源码分析',keepAlive:true  }

        },
        {
          name: 'dynamicAnalysis',
          path: 'dynamicAnalysis',
          component: DynamicAnalysis,
          meta: { title: 'API',keepAlive:true  }

        },
        {
          name: 'dyAna',
          path: 'dyAna',
          component: DyAna,
          meta: { title: '动态解析',keepAlive:true  }
        },
          {
          name: 'model',
          path: 'model',
          component: Model,
          meta: { title: '模型分析',keepAlive:true  }
        },
          {
          name: 'pdf',
          path: 'pdf',
          component: Pdf,
          meta: { title: '导出报告',keepAlive:true  }
        },
      ]
    },
    {
      path: '/xmlcode',
      name: 'xmlcode',
      component: XmlCode,
      meta:{keepAlive:true },
    },
    {
      path: '/javacode',
      name: 'javacode',
      component: JavaCode,
      meta:{keepAlive:true },
    }
  ]
})

router.beforeEach((to, from, next) => {
  // 检查是否正在导航到首页
  if (to.path === '/') {
    sessionStorage.clear();  // 清空 sessionStorage
  }
  next();  // 继续路由导航
});
export default router
